/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-13 07:22:09
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-15 22:51:04
 */
import 'package:flutter/material.dart';
import 'package:flutter_data_center/components/animation_text.dart';
import 'package:flutter_data_center/controller/home_controller.dart';
import 'package:flutter_data_center/model/module/module_statistics_module.dart';
import 'package:get/get.dart';

import '../../../constants.dart';

class ModuleStatistic extends StatelessWidget {
  const ModuleStatistic({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) => GetBuilder<HomeController>(
        builder: (_controller) => _controller.moduleStatisticsList.length > 0
            ? Container(
                width: double.infinity,
                height: 100,
                decoration: BoxDecoration(
                  color: Theme.of(context).primaryColor,
                  borderRadius: BorderRadius.circular(defaultRadius),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    ..._controller.moduleStatisticsList
                        .map((e) => buildItem(e)),
                  ],
                ),
              )
            : Container(
                height: 100, child: Center(child: CircularProgressIndicator())),
      );

  Expanded buildItem(ModuleStatisticModel item) {
    return Expanded(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          AnimText(
            number: item.count,
            style: TextStyle(
              color: Colors.white,
              fontSize: defaultFontSize * 1.8,
            ),
          ),
          Text(
            item.title,
            style: TextStyle(
              fontSize: defaultFontSize * 0.8,
              color: Colors.white,
            ),
          ),
        ],
      ),
    );
  }
}
